<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<% request.setAttribute("ctx",request.getContextPath()); %>
<%@ include file="/header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户注册</title>
<script type="text/javascript">
	function findName(obj){
		var xhr=new XMLHttpRequest();
		var name=obj.value;
		if(name.length==0){
			alert("用户名不能为空！");
			obj.focus();
			return false;
		}
		
		var url="${ctx}/user/manager?func=findName&username=" + name;
		alert(url);
		xhr.open("GET",url,true);
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4 && xhr.status == 200) {
				var responseData = xhr.responseText;
				if(responseData!="null")
				document.getElementById("output").innerHTML =  "用户名已存在";
				obj.focus();
		   }
		};
		xhr.send(null);
		}
	
	</script>
</head>
<body>
<div style="text-align:center;">
  <h1>用户注册</h1>
	<form action="${ctx}/user/manager?func=add" method="post" onsubmit="return validate(this)">
		<p>
			用户名：<input name="username" id="username" type="text" onblur="findName(this)">
		</p>
		<span id="output"></span>
		<p>
			密 &nbsp;码：<input name="password" type="password">
		</p>
		<p>
			<input type="submit" value="注册" />
			<input type="reset" value="重置" />
		</p>
	</form>
	</div>
</body>

	<script type="text/javascript">
	function validate(myform){
		if(myform.password.value.length < 4){
			alert("密码长度不能小于4");
			myform.password.focus();
			return false;
		}
		return true;
		}
	
	
	</script>
</html>
